#include <REGX52.H>
#include "IIC.h"
#include "Delay.h"

#define AT24C02_ADDRESS 0xA0

void AT24C02_WriteByte(unsigned char Address,unsigned char Data)
{
    IIC_Start();
    IIC_SendByte(AT24C02_ADDRESS);
    IIC_ReceiveAck();
    IIC_SendByte(Address);
    IIC_ReceiveAck();
    IIC_SendByte(Data);
    IIC_ReceiveAck();
    IIC_Stop();
    Delay(5);
}

unsigned char AT24C02_ReadByte(unsigned char Address)
{
    unsigned char Data;
    IIC_Start();
    IIC_SendByte(AT24C02_ADDRESS);
    IIC_ReceiveAck();
    IIC_SendByte(Address);
    IIC_ReceiveAck();
    IIC_Start();
    IIC_SendByte((AT24C02_ADDRESS|0x01));
    IIC_ReceiveAck();
    Data=IIC_ReceiveByte();
    IIC_SendAck(1);
    IIC_Stop();
    return Data;
}